const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    "password": "请输入密码",
    "username": "请输入账号"
  },
  checkboxChange: function(e) {},
  userNameInput: function(e) {
    this.setData({
      userName: e.detail.value
    })
  },
  userPasswordInput: function(e) {
    this.setData({
      userPassword: e.detail.value
    })
  },

  logIn: function() {
    app.reqFetch.getSignIN({
      username: this.data.userName,
      password: this.data.userPassword,
      type: 2
    }, (res) => {
      const {
        token,
        userid,
        name,
        username
      } = res
      app.globalData.userId = userid
      app.globalData.userToken = token
      app.globalData.userName = name
      app.globalData.userAccount = username

      if (name === "食堂主厨") {
        app.globalData.userType = 1
        wx.redirectTo({
          url: '/pages/chef-home/chef-home',
        })
      } else if (name === "仓储员") {
        app.globalData.userType = 2
        wx.redirectTo({
          url: '/pages/warehouse-home/warehouse-home',
        })
      } else if (name === "食堂管理员") {
        app.globalData.userType = 3
        wx.redirectTo({
          url: '/pages/admin-home/admin-home',
        })
      } else if (name === "供应商") {
        app.globalData.userType = 4
        wx.redirectTo({
          url: '/pages/supplier-home/supplier-home',
        })
      } else if (name === "监管员") {
        app.globalData.userType = 5
        wx.redirectTo({
          url: '/pages/regulation-home/regulation-home',
        })
      } else if (name === "财务"){
        app.globalData.userType = 6
        wx.redirectTo({
          url: '/pages/finance-home/finance-home',
        })
      }

    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    // this.getSign()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {},

})